package com.swh.service.Impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.swh.dao.SysOfficeDao;
import com.swh.entity.QualificationCondition;
import com.swh.entity.SysOffice;
import com.swh.service.SysOfficeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: swh
 * @Description:
 * @Date: 2020/12/14 14:46
 * @Version: 1.0
 */
@Service
public class SysOfficeServiceImpl extends BaseServiceImpl<SysOffice> implements SysOfficeService {

    @Autowired
    public SysOfficeServiceImpl(SysOfficeDao sysOfficeDao) {
        super(sysOfficeDao);
    }

    @Autowired
    private SysOfficeDao sysOfficeDao;

//    @Autowired
//    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public PageInfo<HashMap> selectPage(Integer pageNum, Integer pageSize, QualificationCondition condition) {
        PageHelper.startPage(pageNum, pageSize);
        List<HashMap> list = sysOfficeDao.selectPage((pageNum - 1) * pageSize, pageSize, condition);
        return new PageInfo<>(list);
    }

    @Override
    //旧版本写法
//    @Cacheable(cacheNames = Office.SYS_OFFICE_KEY,key = "'"+Office.SYS_OFFICE_KEY+"findAll'+#sysOffice")

    //新版本写法
//    @Cacheable(cacheNames = Office.SYS_OFFICE_KEY,key ="'findAll'+#sysOffice")
    public List<SysOffice> findAll(SysOffice sysOffice) {
//        List<SysOffice> list ;
//        ValueOperations<String, Object> forValue = redisTemplate.opsForValue();
//        Boolean hasKey = redisTemplate.hasKey(Office.SYS_OFFICE_KEY);
//        if(!hasKey){
//            list=sysOfficeDao.findAll(sysOffice);
//            forValue.set(Office.SYS_OFFICE_KEY,list);
//        }else{
//            list = (List<SysOffice>) forValue.get(Office.SYS_OFFICE_KEY);
//        }
//        return list;
        return sysOfficeDao.findAll(sysOffice);
    }

    @Override
    public int update2(SysOffice sysOffice) {
        return sysOfficeDao.update2(sysOffice);
    }
}
